Socket
Socket
Sign inDemoInstall

@types/cls-hooked

Package Overview
Dependencies
2
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @types/cls-hooked

TypeScript definitions for cls-hooked


Version published
Weekly downloads
880K
decreased by-1.25%
Maintainers
1
Created
Weekly downloads
 

Package description

What is @types/cls-hooked?

@types/cls-hooked provides TypeScript type definitions for the cls-hooked package, which is used for context propagation across asynchronous calls in Node.js. It allows you to create a context that can be accessed throughout the lifecycle of a request, even across asynchronous boundaries.

What are @types/cls-hooked's main functionalities?

Creating a Namespace

This feature allows you to create a new namespace. A namespace is a context that can be used to store and retrieve data across asynchronous calls.

const cls = require('cls-hooked');
const namespace = cls.createNamespace('myNamespace');

Setting and Getting Context

Within a namespace, you can set and get values that will be available throughout the lifecycle of the asynchronous operations.

namespace.run(() => {
  namespace.set('key', 'value');
  console.log(namespace.get('key')); // Outputs: value
});

Binding Functions to a Namespace

You can bind functions to a namespace so that they have access to the context set within that namespace.

const boundFunction = namespace.bind(() => {
  console.log(namespace.get('key'));
});
namespace.run(() => {
  namespace.set('key', 'value');
  boundFunction(); // Outputs: value
});

Other packages similar to @types/cls-hooked

Readme

Source

Installation

npm install --save @types/cls-hooked

Summary

This package contains type definitions for cls-hooked (https://github.com/jeff-lewis/cls-hooked).

Details

Files were exported from https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/cls-hooked.

index.d.ts

/// <reference types="node" />

import { EventEmitter } from "events";

export interface Namespace<N = Record<string, any>> {
    active: any;

    set<K extends keyof N = keyof N>(key: K, value: N[K]): N[K];
    get<K extends keyof N = keyof N>(key: K): N[K];
    run(fn: (...args: any[]) => void): void;
    runAndReturn<T>(fn: (...args: any[]) => T): T;
    runPromise<T>(fn: (...args: any[]) => Promise<T>): Promise<T>;
    bind<F extends Function>(fn: F, context?: any): F; // tslint:disable-line: ban-types
    bindEmitter(emitter: EventEmitter): void;
    createContext(): any;
    enter(context: any): void;
    exit(context: any): void;
}

// eslint-disable-next-line @definitelytyped/no-unnecessary-generics
export function createNamespace<N = Record<string, any>>(name: string): Namespace<N>;
// eslint-disable-next-line @definitelytyped/no-unnecessary-generics
export function getNamespace<N = Record<string, any>>(name: string): Namespace<N> | undefined;
export function destroyNamespace(name: string): void;
export function reset(): void;

Additional Details

  • Last updated: Mon, 06 Nov 2023 22:41:05 GMT
  • Dependencies: @types/node

Credits

These definitions were written by Leo Liang, and Lucian Buzzo.

FAQs

Last updated on 07 Nov 2023

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc